home *** CD-ROM | disk | FTP | other *** search
/ Family Forum 261 / SOMC Family Forum 261.iso / Xtras / Animation Wizard.dir / 00009_Script_Zooms < prev    next >
Text File  |  1997-05-10  |  13KB  |  421 lines

  1. -- Zooms script
  2.  
  3. property ioFieldList
  4. property iFieldFocus
  5. property ioFieldFocus
  6. property iCurrentMotionStyleIndex
  7. property iCurrentVisualStyleIndex
  8.  
  9. -- The motion styles are:
  10. property ikMotionIn  -- 1
  11. property ikMotionOut  -- 2
  12. property ikMotionOutThenIn  -- 3
  13. property ikMotionInThenOut  -- 4
  14.  
  15. property iFirstTIme
  16. property iSaveSeconds
  17. property iSaveFPS
  18. property iSaveBaseline
  19. property iSaveDelayEnter
  20. property iSaveDelayHold
  21. property iSaveMark
  22. property iSaveCycles
  23. property iSaveSizeMin
  24. property iSaveSizeMax
  25.  
  26.  
  27. on birth me
  28.   global goZoomsText
  29.   global goSeconds
  30.   global goFPS
  31.   global goBaseLine
  32.   global goSizeMin
  33.   global goSizeMax
  34.   global goDelayEnter
  35.   global goDelayHold
  36.   global goCycles
  37.   
  38.   set ioFieldList = [goZoomsText, goSeconds, goFPS, goSizeMin, goSizeMax,¼
  39.                               goBaseLine, goDelayEnter, goDelayHold, goCycles]
  40.   set ikMotionIn = 1
  41.   set ikMotionOut = 2
  42.   set ikMotionOutThenIn = 3
  43.   set ikMotionInThenOut = 4
  44.   
  45.   set iCurrentMotionStyleIndex = ikMotionIn
  46.   set iCurrentVisualStyleIndex = 1
  47.   set iFieldFocus = 1
  48.   set iFirstTime = TRUE
  49.   
  50.   return me
  51. end birth
  52.  
  53. on mInit me
  54.   global goSeconds
  55.   global goFPS
  56.   global goBaseLine
  57.   global goSizeMin
  58.   global goSizeMax
  59.   global goDelayEnter
  60.   global goDelayHold
  61.   global goCycles
  62.   global goZooms
  63.   global goMarkFrame
  64.   global goVisualStyles
  65.   global goMotionStyles
  66.   global goScoreMgr
  67.   
  68.   -- CheckMark parameter: channel
  69.   mInit(goMarkFrame, 4)  -- channel
  70.   
  71.   if iFirstTime then  -- use intellegent defaults
  72.     mSetValue(goSeconds, 5)
  73.     mSetValue(goFPS, 5)
  74.     set defaultBaseLine = integer(mGetStageHeight(goScoreMgr) / 2)
  75.     mSetValue(goBaseLine, defaultBaseLine)
  76.     mSetValue(goSizeMin, 1)
  77.     mSetValue(goSizeMax, 100)
  78.     mSetValue(goDelayEnter, 0)
  79.     mSetValue(goDelayHold, 0)
  80.     mSetValue(goCycles, 1)
  81.     mSetValue(goMarkFrame, TRUE)
  82.     set iFirstTime = FALSE
  83.     
  84.   else  -- use values saved from when we last left
  85.     mSetValue(goSeconds, iSaveSeconds)
  86.     mSetValue(goFPS, iSaveFPS)
  87.     mSetValue(goBaseLine, iSaveBaseline)
  88.     mSetValue(goSizeMin, iSaveSizeMin)
  89.     mSetValue(goSizeMax, iSaveSizeMax)
  90.     mSetValue(goDelayEnter, iSaveDelayEnter)
  91.     mSetValue(goDelayHold, iSaveDelayHold)
  92.     mSetValue(goCycles, iSaveCycles)
  93.     mSetValue(goMarkFrame, iSaveMark)
  94.   end if
  95.   
  96.   set ioFieldFocus = GetAt(ioFieldList, iFieldFocus)
  97.   
  98.   -- RadioButtons parameters: channel, nChannels, rightAnswer, default
  99.   set goMotionStyles = 0
  100.   set goMotionStyles = birth(script "RadioButton",  26, 4, 0, iCurrentMotionStyleIndex)
  101.   
  102.   -- VisualStyles Params: castNum, default, nItems, channel
  103.   if the machineType < 256 then
  104.     mInit(goVisualStyles, the number of cast "ZoomsVisualStylesMac", ¼
  105.                iCurrentVisualStyleIndex, 8, 19)
  106.   else
  107.     mInit(goVisualStyles, the number of cast "ZoomsVisualStylesPC", ¼
  108.                iCurrentVisualStyleIndex, 8, 19)
  109.   end if
  110.   
  111.   -- For keystroke validity checking
  112.   set the keydownscript =  "mCheckKey(goZooms)"
  113.   
  114. end mInit 
  115.  
  116. on mSetFieldFocus me, oWhom
  117.   set where = getOne(ioFieldList, oWhom)
  118.   if where = 0 then
  119.     alert("Internal error - mSetFieldFocus could not find object")
  120.     return
  121.   end if
  122.   
  123.   set iFieldFocus = where  
  124.   set ioFieldFocus = GetAt(ioFieldList, iFieldFocus)
  125.   
  126. end mSetFieldFocus
  127.  
  128. on mCheckKey me
  129.   if the Key = TAB then -- change focus to the next field
  130.     set iFieldFocus = IncrMod(iFieldFocus, count(ioFieldList))
  131.     set ioFieldFocus = GetAt(ioFieldList, iFieldFocus)
  132.     pass  -- pass the event so the hilight goes to the next field  
  133.   else
  134.     if iFieldFocus = 1 then -- the text entry field, allow anything
  135.       pass
  136.     else  -- numeric fields, only allow digits
  137.       if (offset(the key, "0123456789") > 0) or (the key = BACKSPACE)  then
  138.         pass
  139.       else
  140.         dontPassEvent -- restrict only to digits.
  141.       end if
  142.     end if
  143.   end if
  144. end mCheckKey
  145.  
  146. on mSetNewMotionStyle me, theNewStyleIndex
  147.   set iCurrentMotionStyleIndex = theNewStyleIndex
  148. end mSetNewMotionStyle
  149.  
  150. on mSetNewVisualStyle me, theNewStyleIndex
  151.   set iCurrentVisualStyleIndex = theNewStyleIndex
  152. end mSetNewVisualStyle
  153.  
  154.  
  155.  
  156. on mValidate me
  157.   global goSizeMin
  158.   global goSizeMax
  159.   
  160.   if mGetValue(goSizeMin) > mGetValue(goSizeMax) then
  161.     alert("The minimum size must be less than the maximum size.")
  162.     return FALSE
  163.   end if
  164.   
  165.   -- Attempt to validate the last field of focus
  166.   set lastFieldOKFlag = mValidate(ioFIeldFocus)
  167.   return lastFieldOKFlag
  168. end mValidate
  169.  
  170.  
  171. on mCreate me
  172.   global goMarkFrame
  173.   global goMotionStyles
  174.   global goVisualStyles
  175.   global goScoreMgr
  176.   global goCastMgr
  177.   global gDevelopmentFlag
  178.   global gCastNumTextAsBitmap
  179.   global goPlatform
  180.   
  181.   if not(mValidate(me)) then
  182.     return
  183.   end if
  184.   if field("ZoomsText") = EMPTY then
  185.     alert("Please enter some text for the Zoom.")
  186.     return
  187.   end if
  188.   
  189.   tell the stage
  190.     set theStageFrame = the frame
  191.   end tell
  192.   
  193.   set castNumVisualStyle = mGetCastNum(goVisualStyles, iCurrentVisualStyleIndex)
  194.   set theVisualStyleName = the name of cast castNumVisualStyle
  195.   set theFont = word 2 of theVisualStyleName
  196.   set theSize = word 3 of theVisualStyleName
  197.   set theSeconds = integer(field "Seconds")
  198.   
  199.   set fps = integer(field "FPS")
  200.   set baseLine = integer(field "BaseLine")
  201.   set delayEnter = integer(field "DelayEnter")
  202.   set delayHold = integer(field "DelayHold")
  203.   set nCycles = integer(field "Cycles")
  204.   set markFirst = mGetValue(goMarkFrame)
  205.   set sizeMin = integer(field "SizeMin")
  206.   set sizeMax = integer(field "SizeMax")
  207.   set nFrames = integer(theSeconds * fps)
  208.   
  209.   
  210.   -- Call the ScoreMgr to set up the score, # of frames, and 1 channel
  211.   --  set nTotalFrames = (delayEnter + nFrames + delayHold) * nCycles
  212.   
  213.   if delayHold > 0 then
  214.     set nTotalFrames = (nFrames + 1)*nCycles
  215.   else
  216.     set nTotalFrames = nFrames*nCycles
  217.   end if
  218.   
  219.   if not(mInit(goScoreMgr, nTotalFrames, 1)) then
  220.     return
  221.   end if
  222.   
  223.   set theCh = mGetNextSelectedChannel(goScoreMgr)
  224.   set theFrameNum = mGetStartFrame(goScoreMgr)
  225.   
  226.   set castNumSource = mModifyRichTextCM(goCastMgr, ¼
  227.                 the text of field "ZoomsText", theFont, theSize)
  228.   if castNumSource = 0 then  -- error
  229.     return
  230.   end if  
  231.   
  232.   -- The following does an effective "Convert to bitmap" into a 
  233.   -- known bitmap cast member.
  234.   set the picture of member gCastNumTextAsBitmap = ¼
  235.         the picture of member castNumSource
  236.   set widthOfTextAsBitmap = float(the width of member gCastNumTextAsBitmap)
  237.   set heightOfTextAsBitmap = float(the height of member gCastNumTextAsBitmap)
  238.   
  239.   
  240.   -- Do specific calculations depending on motion style  
  241.   
  242.   set pctMin = float(sizeMin) / 100.
  243.   set pctMax = float(sizeMax) / 100.
  244.   set pctInc = (pctMax - pctMin) / float(nFrames - 1)
  245.   
  246.   
  247.   if (iCurrentMotionStyleIndex = ikMotionIn)  or (iCurrentMotionStyleIndex = ikMotionOut) then    
  248.     set nFrames1 = nFrames
  249.     set nFrames2 = 0
  250.   else
  251.     set nFrames1 = integer(nFrames / 2)
  252.     set nFrames2 = nFrames - nFrames1
  253.     set pctInc = pctInc * 2  -- must double to do this in half the frames
  254.   end if
  255.   
  256.   if (iCurrentMotionStyleIndex = ikMotionIn) or ¼
  257.       (iCurrentMotionStyleIndex = ikMotionInThenOut) then 
  258.     
  259.     set pctStart1 = pctMin
  260.     set pctInc1 = pctInc
  261.     set pctStart2 = pctMax
  262.     set pctInc2 = pctInc * -1.0
  263.     
  264.   else  -- Out or OutThenIn
  265.     set pctStart1 = pctMax
  266.     set pctInc1 = pctInc * -1.0
  267.     set pctStart2 = pctMin
  268.     set pctInc2 = pctInc
  269.     
  270.   end if
  271.   
  272.   set theForeColor  = 255
  273.   set theBackColor  = 0
  274.   
  275.   --  Copy the cast member into the source movie's cast
  276.   
  277.   set castNumTarget = mFindFreeCastRun(goCastMgr, 1, 1)
  278.   copyToClipBoard member gCastNumTextAsBitmap
  279.   tell the stage
  280.     pasteClipboardInto member castNumTarget
  281.     set the name of member castNumTarget  = "BitMap" && string(the ticks)
  282.   end tell
  283.   
  284.   --  Finally we are ready to generate frames
  285.   -- initialize list of frames to record in
  286.   set frameList  = []
  287.   repeat with i = theFrameNum  to  (theFrameNum + nTotalFrames  - 1)
  288.     add(frameList, [i])
  289.   end repeat
  290.   
  291.   -- Mark first frame upon request
  292.   if markFirst  then
  293.     set firstFrame = getAt(frameList, 1)
  294.     set theLabel  = "AW.Zoom." & word 1 of the text of field "ZoomsText" & " " & ¼
  295.               mGetGeneratedScoreSelection(goScoreMgr)
  296.     add(firstFrame,  [#label, theLabel])
  297.     setAt(frameList, 1, firstFrame)
  298.   end if
  299.   
  300.   -- Generate the score fragment
  301.   set relFrameCount = 1
  302.   repeat with thisCycle = 1 to nCycles
  303.     set xLoc = round(mGetStageWidth(goScoreMgr) / 2)
  304.     set yLoc = baseline    
  305.     
  306.     set currentPct = pctStart1
  307.     set theWidth = currentPct * widthOfTextAsBitmap
  308.     set theHeight = currentPct * heightOfTextAsBitmap
  309.     
  310.     -- Insert delay at entry upon request  
  311.     set firstFrame = getAt( frameList, relFrameCount)
  312.     set secondFrame = getAt( frameList, relFrameCount + 1)
  313.     if delayEnter > 0 then
  314.       add(firstFrame, [#tempo, -delayEnter])
  315.       add(secondFrame, [#tempo, fps])
  316.     else 
  317.       add(firstFrame, [#tempo, fps])
  318.       add(secondFrame, [#tempo, 0])
  319.     end if
  320.     setAt(frameList, relFrameCount, firstFrame)
  321.     setAt(frameList,relFrameCount + 1, secondFrame)
  322.     
  323.     -- Generate the first part of the zoom
  324.     repeat with thisFrame = 1 to nFrames1
  325.       set theWidth = integer(theWidth +.49)
  326.       set theHeight = integer(theHeight + .49)
  327.       set currentFrame = getAt(frameList,relFrameCount)
  328.       add(currentFrame, [#sprite, theCh, castNumTarget, theForeColor, theBackColor, xLoc, yLoc, theWidth, theHeight ])  
  329.       --      mWriteSpriteRange(goScoreMgr, theFrameNum, theCh, castNumTarget, ¼
  330. --                     theForeColor, theBackColor, xLoc, yLoc, theWidth, theHeight)      
  331.       setAt(frameList, relFrameCount, currentFrame)
  332.       set theFrameNum = theFrameNum + 1
  333.       set currentPct = currentPct + pctInc1
  334.       set theWidth = currentPct * widthOfTextAsBitmap
  335.       set theHeight = currentPct * heightOfTextAsBitmap
  336.       set relFrameCount = relFrameCount + 1
  337.     end repeat
  338.     
  339.     -- insert delay  upon request
  340.     
  341.     if delayHold > 0 then
  342.       set currentFrame = getAt(frameList,relFrameCount)
  343.       add(currentFrame, [#tempo, -delayHold])
  344.       set theWidth = integer(theWidth +.49)
  345.       set theHeight = integer(theHeight + .49)
  346.       add(currentFrame, [#sprite, theCh, castNumTarget, theForeColor, theBackColor, xLoc, yLoc, theWidth, theHeight ])
  347.       --      mWriteSprite(goScoreMgr, theFrameNum, theCh, castNumTarget, ¼
  348. --                     theForeColor, theBackColor, xLoc, yLoc, integer(theWidth), integer(theHeight))
  349.       setAt(frameList, relFrameCount, currentFrame)
  350.       set theFrameNum = theFrameNum + 1
  351.       set relFrameCount = relFrameCount + 1
  352.     end if
  353.     
  354.     -- Generate the second part of the zoom if there is one
  355.     if nFrames2 > 0 then
  356.       set currentPct = pctStart2
  357.       set theWidth = currentPct * widthOfTextAsBitmap
  358.       set theHeight = currentPct * heightOfTextAsBitmap
  359.       --      mWriteFrameTempo(goScoreMgr, theFrameNum, fps)
  360.       repeat with thisFrame = 1 to nFrames2
  361.         set theWidth = integer(theWidth +.49)
  362.         set theHeight = integer(theHeight + .49)
  363.         set currentFrame = getAt(frameList, relFrameCount)
  364.         add(currentFrame, [#sprite, theCh, castNumTarget, theForeColor, theBackColor, xLoc, yLoc, theWidth, theHeight ])  
  365.         --        mWriteSpriteRange(goScoreMgr, theFrameNum, theCh, castNumTarget, ¼
  366. --                     theForeColor, theBackColor, xLoc, yLoc, theWidth, theHeight) 
  367.         setAt(frameList, relFrameCount, currentFrame)
  368.         set theFrameNum = theFrameNum + 1
  369.         set currentPct = currentPct + pctInc2
  370.         set theWidth = currentPct * widthOfTextAsBitmap
  371.         set theHeight = currentPct * heightOfTextAsBitmap
  372.         set relFrameCount = relFrameCount + 1
  373.       end repeat
  374.     end if
  375.     
  376.   end repeat  -- nCycles
  377.   
  378.   mWriteFrame(goScoreMgr, frameList)
  379.   
  380.   set labelName = "Zooms" & goPlatform
  381.   go  label(labelName) + 2  -- to display reselect button
  382.   
  383.   if not(gDevelopmentFlag) then
  384.     tell the stage
  385.       go frame theStageFrame
  386.     end tell
  387.   end if 
  388.   
  389.   mClean(goScoreMgr)
  390.   
  391. end mCreate
  392.  
  393.  
  394.  
  395. on mCleanup me
  396.   global goMotionStyles
  397.   global goSeconds
  398.   global goFPS
  399.   global goBaseLine
  400.   global goSizeMin
  401.   global goSizeMax
  402.   global goDelayEnter
  403.   global goDelayHold
  404.   global goCycles
  405.   global goMarkFrame
  406.   
  407.   mCleanup(goMotionStyles)
  408.   
  409.   set iSaveSeconds =  mGetValue(goSeconds)
  410.   set iSaveFPS = mGetValue(goFPS)
  411.   set iSaveBaseLine = mGetValue(goBaseLine)
  412.   set iSaveSizeMin = mGetValue(goSizeMin)
  413.   set iSaveSizeMax = mGetValue(goSizeMax)
  414.   set iSaveDelayEnter = mGetValue(goDelayEnter)
  415.   set iSaveDelayHold = mGetValue(goDelayHold)
  416.   set iSaveCycles = mGetValue(goCycles)  
  417.   set iSaveMark = mGetValue(goMarkFrame)  
  418.   mCleanup(goMarkFrame)
  419. end mCleanup
  420.  
  421.